﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.effects {
    import Engine.Classes.*;
    import Engine.Events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Classes.*;
    import __AS3__.vec.*;
    import com.greensock.*;
    import Engine.*;
    import com.greensock.easing.*;

    public class BounceAnimationEffect extends AnimationEffect {

        private var m_animTimeline:TimelineLite;
        private var m_spark:DisplayObject;
        private var m_isFirstReattach:Boolean;
        private var m_animProxyValues:ProxyValues;
        private var m_useHotspot:Boolean;

        public function BounceAnimationEffect(_arg1:MapResource, _arg2:String, _arg3:Boolean=false){
            super(_arg1, _arg2, _arg3, true);
            this.m_spark = new EmbeddedArt.spark();
            this.m_isFirstReattach = true;
            this.m_animProxyValues = new ProxyValues();
        }
        public function set useHotspot(_arg1:Boolean):void{
            this.m_useHotspot = _arg1;
        }
        private function beginBounceAnimation():void{
            var _local1:Point;
            var _local2:Point;
            var _local3:Point;
            var _local4:Point;
            var _local5:Point;
            var _local6:Vector.<Vector3>;
            var _local7:Vector3;
            var _local8:Vector2;
            var _local9:Point;
            var _local10:Point;
            if (m_effectImage){
                _local1 = new Point((m_mapResource.content.width >> 1), 0);
                if (this.m_useHotspot){
                    _local6 = m_mapResource.getHotspots();
                    _local7 = m_mapResource.getHotspots()[(_local6.length - 1)];
                    _local8 = IsoMath.tilePosToPixelPos(_local7.x, _local7.y);
                    _local9 = IsoMath.viewportToStage(_local8);
                    _local10 = m_mapResource.content.globalToLocal(_local9);
                    _local1.x = _local10.x;
                };
                _local2 = new Point(_local1.x, (_local1.y - 20));
                _local3 = new Point(_local1.x, (_local1.y - 60));
                _local4 = new Point(-((m_effectImage.width >> 1)), -((m_effectImage.height >> 1)));
                _local5 = new Point(-((this.m_spark.width >> 1)), -((this.m_spark.height >> 1)));
                m_effectImage.x = (_local1.x + _local4.x);
                m_effectImage.y = (_local1.y + _local4.y);
                this.m_animProxyValues.x = m_effectImage.x;
                this.m_animProxyValues.y = m_effectImage.y;
                this.m_animProxyValues.scaleX = m_effectImage.scaleX;
                this.m_animProxyValues.scaleY = m_effectImage.scaleY;
                this.m_animProxyValues.alpha = m_effectImage.alpha;
                this.m_spark.x = _local2.x;
                this.m_spark.y = _local2.y;
                this.m_spark.scaleX = (this.m_spark.scaleY = 0);
                this.m_animTimeline = new TimelineLite({
                    onComplete:this.endItAll,
                    onUpdate:this.proxyUpdate
                });
                this.m_animTimeline.appendMultiple([new TweenLite(this.m_animProxyValues, 0.3, {
                    y:(_local3.y + _local4.y),
                    ease:Quad.easeOut
                }), new TweenLite(this.m_animProxyValues, 0.3, {
                    y:(_local2.y + _local4.y),
                    ease:Quad.easeIn
                }), new TweenLite(this.m_animProxyValues, 0.5, {
                    scaleX:2,
                    scaleY:2,
                    x:(_local2.x - m_effectImage.width),
                    y:(_local2.y - m_effectImage.height),
                    alpha:0,
                    delay:0.5
                }), new TweenLite(this.m_spark, 0.001, {
                    scaleX:1,
                    scaleY:1,
                    x:(_local2.x + _local5.x),
                    y:(_local2.y + _local5.y),
                    onStart:this.onSparkInit
                }), new TweenLite(this.m_spark, 0.2, {
                    scaleX:0,
                    scaleY:0,
                    x:_local2.x,
                    y:_local2.y
                })], 0, TweenAlign.SEQUENCE);
            };
        }
        override public function updateAnimatedBitmap(_arg1:Number):void{
            super.updateAnimatedBitmap(_arg1);
        }
        private function proxyUpdate():void{
            if (m_effectImage){
                m_effectImage.x = this.m_animProxyValues.x;
                m_effectImage.y = this.m_animProxyValues.y;
                m_effectImage.scaleX = this.m_animProxyValues.scaleX;
                m_effectImage.scaleY = this.m_animProxyValues.scaleY;
                m_effectImage.alpha = this.m_animProxyValues.alpha;
            };
        }
        private function onSparkInit():void{
            getAttachParent().addChild(this.m_spark);
        }
        private function endItAll():void{
            var _local1:AnimatedBitmap;
            if (((this.m_spark) && (this.m_spark.parent))){
                this.m_spark.parent.removeChild(this.m_spark);
            };
            if (m_effectImage){
                _local1 = (m_effectImage as AnimatedBitmap);
                _local1.stop();
                m_mapResource.removeAnimatedEffects();
                m_isActive = false;
            };
        }
        override public function cleanUp():void{
            if (this.m_animTimeline){
                this.m_animTimeline.kill();
            };
            super.cleanUp();
        }
        override protected function onItemImageLoaded(_arg1:LoaderEvent):void{
            super.onItemImageLoaded(_arg1);
            this.beginBounceAnimation();
        }

    }
}//package Classes.effects 

class ProxyValues {

    public var x:Number;
    public var y:Number;
    public var scaleX:Number;
    public var scaleY:Number;
    public var alpha:Number;

    public function ProxyValues(){
    }
}
